package se.webbzon.oschi01.gui;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;

import se.webbzon.oschi01.nbt.Tag;

public class NBTTransferable implements Transferable, Cloneable {
	
	public static DataFlavor dataFlavor = new DataFlavor(NBTTransferable.class,null);
	
	private static DataFlavor[] flavors = {dataFlavor};
	
	private Tag<?> root;
	
	public NBTTransferable(Tag<?> root) {
		this.root = root;
	}
	
	public Tag<?> getRoot() {
		return root;
	}
	
	@Override public DataFlavor[] getTransferDataFlavors() {
		return flavors;
	}

	@Override public boolean isDataFlavorSupported(DataFlavor flavor) {
		return flavor.getRepresentationClass() == NBTTransferable.class;
	}

	@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
		if (isDataFlavorSupported(flavor))
			return clone();
		else
			throw new UnsupportedFlavorException(flavor);
	}

	@Override public NBTTransferable clone() {
		return new NBTTransferable(root.clone());
	}

}
